package server.controller.news;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import server.db.primary.mapper.map.NewsAppMapper;
import server.db.primary.mapper.map.NewsMapper;
import server.db.primary.model.map.Affiche;
import server.db.primary.model.map.News;

import server.db.primary.model.map.NewsApp;

import server.tool.Res;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController

public class NewsController {


    @Autowired
     NewsMapper newsMapper;

    @Autowired
    NewsAppMapper newsAppMapper;

    /**
     * 查询全部的新闻信息
     * @return
     */
    @ResponseBody
    @RequestMapping("/News/All")
    public Res NewsByAll() {
        List<News> news = newsMapper.selectByAll();
        return Res.success(news);
    }

    /**
     * 根据id查询
     * @return
     */
    @RequestMapping("/News/ById")
    public Res NewsById(Long id) {
        News news1 = newsMapper.selectByPrimaryKey(id);
        return Res.success(news1);
    }

    /**
     *新闻插入
     * @param record
     * @return
     */
    @RequestMapping("/News/NewsInsert")
    public Res NewsInsert( News record) {
        int News=newsMapper.insertSelective(record);
        return Res.success(News);
    }

    /**
     * 新闻修改
     * @param record
     * @return
     */
    @RequestMapping("/News/NewsUpdate")
    public Res NewsUpdate( News record) {
        int News=newsMapper.updateByPrimaryKeySelective(record);
        return Res.success(News);
    }

    /**
     * 新闻删除
     * @param id
     * @return
     */
    @RequestMapping("/News/DeleteNews")
    public Res DeleteNews(Long id) {
        int News=newsMapper.deleteByPrimaryKey(id);
        return Res.success(News);
    }

    /**
     * 查询最后一条数据的流水号
     * @return
     */
    @RequestMapping("/News/numberId")
    public Res newsBynumberId() {
        List<News> news = newsMapper.selectBynumberId();
        return Res.success(news);
    }


    @RequestMapping("/News/userId")
    public Res newsByuserId(Integer mark1,Integer userId,String timeStart, String timeEnd) {
        List<News> news = newsMapper.selectByuserId(userId,mark1,timeStart,timeEnd);
        return Res.success(news);
    }

    /**
     * 根据流水号查找附件
     * @param id
     * @return
     */
    @RequestMapping("/News/selectNewsApp")
    public Res selectNewsApp(Long id) {
        /**
         * 根据id查找,返回流水号
         */
        News  news=newsMapper.selectByPrimaryKey(id);
        /**
         * 获得news表中的numberID
         */

        Long numberId=news.getNumberId();

        /**
         * 根据流水号查找对应的附件全部传到前端
         */
        List<NewsApp> list=newsAppMapper.selectByNumberId(numberId);

        Map<String, Object> map = new HashMap<>();
        map.put("news",news);
        map.put("newsApp",list);

        return Res.success(map);

    }

    /**
     * 部门领导查询（待办）
     * @param userId
     * @param wellUserId
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/News/notwelluserId")
    public Res sealnotBywelluserId(Integer userId,Integer wellUserId,String timeStart, String timeEnd,String timeStart1, String timeEnd1) {
        List<News> news = newsMapper.selectnotBywelluserId(userId,wellUserId,timeStart, timeEnd,timeStart1, timeEnd1);
        return Res.success(news);
    }

    /**
     * 部门领导查询(已办)
     * @param userId
     * @param wellUserId
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/News/welluserId")
    public Res sealBywelluserId(Integer userId,Integer wellUserId,String timeStart, String timeEnd,String timeStart1, String timeEnd1) {
        List<News> news = newsMapper.selectBywelluserId(userId,wellUserId,timeStart, timeEnd,timeStart1, timeEnd1);
        return Res.success(news);
    }

    /**
     * 部门领导查询（办结）
     * @param userId
     * @param wellUserId
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/News/welluserIdmark")
    public Res sealBywelluserIdmark(Integer userId,Integer wellUserId,String timeStart, String timeEnd,String timeStart1, String timeEnd1) {
        List<News> news = newsMapper.selectBywelluserIdmark(userId,wellUserId,timeStart, timeEnd,timeStart1, timeEnd1);
        return Res.success(news);
    }

    /**
     * 公司领导查询(办结)
     * @param stationUserId
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/News/stationuserIdmark")
    public Res sealBystationuserIdmark(Integer stationUserId,String timeStart, String timeEnd) {
        List<News> news = newsMapper.selectBystationuserIdmark(stationUserId,timeStart, timeEnd);
        return Res.success(news);
    }

    /**
     * 公司领导查询（已办）
     * @param stationUserId
     * @param timeStart
     * @param timeEnd
     * @return
     */

    @RequestMapping("/News/stationuserId")
    public Res sealBystationuserId(Integer stationUserId,String timeStart, String timeEnd) {
        List<News> news = newsMapper.selectBystationuserId(stationUserId,timeStart, timeEnd);
        return Res.success(news);
    }

    /**
     * 公司领导查询（待办）
     * @param stationUserId
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/News/notstationuserId")
    public Res sealnotBystationuserId(Integer stationUserId,String timeStart, String timeEnd) {
        List<News> news = newsMapper.selectnotBystationuserId(stationUserId,timeStart, timeEnd);
        return Res.success(news);
    }

    /**
     * 编辑干事查询（办结）
     * @param editUserId
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/News/editUserIdmark")
    public Res selecteditUserIdmark(Integer userId,Integer editUserId,String timeStart, String timeEnd) {
        List<News> news = newsMapper.selecteditUserIdmark(userId,editUserId,timeStart, timeEnd);
        return Res.success(news);
    }

    /**
     * 编辑干事查询（待办）
     * @param editUserId
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/News/selectnotByeditUserId")
    public Res selectnotByeditUserId(Integer userId,Integer editUserId,String timeStart, String timeEnd) {
        List<News> news = newsMapper.selectnotByeditUserId(userId,editUserId,timeStart, timeEnd);
        return Res.success(news);
    }

    /**
     * 党群工作部查询（办结）
     * @param partyUserId
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/News/selectpartyUserIdmark")
    public Res selectpartyUserIdmark(Integer partyUserId,String timeStart, String timeEnd,Integer userId,Integer wellUserId,String timeStart1, String timeEnd1) {
        List<News> news = newsMapper.selectpartyUserIdmark(partyUserId,timeStart, timeEnd,userId,wellUserId,timeStart1, timeEnd1);
        return Res.success(news);
    }
    /**
     * 党群工作部查询（已办）
     * @param partyUserId
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/News/selectBypartyUserId")
    public Res selectBypartyUserId(Integer partyUserId,String timeStart, String timeEnd,Integer userId,Integer wellUserId,String timeStart1, String timeEnd1) {
        List<News> news = newsMapper.selectBypartyUserId(partyUserId,timeStart, timeEnd,userId,wellUserId,timeStart1, timeEnd1);
        return Res.success(news);
    }

    /**
     * 党群工作部查询（待办）
     * @param partyUserId
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/News/selectnotBypartyUserId")
    public Res selectnotBypartyUserId(Integer partyUserId,String timeStart, String timeEnd,Integer userId,Integer wellUserId,String timeStart1, String timeEnd1) {
        List<News> news = newsMapper.selectnotBypartyUserId(partyUserId,timeStart, timeEnd,userId,wellUserId,timeStart1, timeEnd1);
        return Res.success(news);
    }

    /**
     * 监控流程
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/News/mark")
    public Res sealBymark(String timeStart, String timeEnd) {
        List<News> news = newsMapper.selectBymark(timeStart, timeEnd);
        return Res.success(news);
    }

    /**
     * 权限查找
     * @param mark
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/News/notmark")
    public Res sealBynotmark(Integer mark,String timeStart, String timeEnd) {
        List<News> news = newsMapper.selectnotBymark(mark,timeStart, timeEnd);
        return Res.success(news);
    }
    /**
     * 申请人归档信息
     * @param userId
     * @param timeStart
     * @param timeEnd
     * @return
     */
    @RequestMapping("/News/selectUserId")
    public Res selectUserId(Integer userId,String timeStart ,String timeEnd) {
        List<News> news = newsMapper.selectUserId(userId, timeStart, timeEnd);
        return Res.success(news);
    }


}
